package com.healthy.social.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.healthy.common.log.annotation.Log;
import com.healthy.common.log.enums.BusinessType;
import com.healthy.common.security.annotation.RequiresPermissions;
import com.healthy.social.domain.Circles;
import com.healthy.social.service.ICirclesService;
import com.healthy.common.core.web.controller.BaseController;
import com.healthy.common.core.web.domain.AjaxResult;
import com.healthy.common.core.utils.poi.ExcelUtil;
import com.healthy.common.core.web.page.TableDataInfo;

/**
 * 用户圈子Controller
 * 
 * @author 束伟
 * @date 2024-03-29
 */
@RestController
@RequestMapping("/Circles")
public class CirclesController extends BaseController
{
    @Autowired
    private ICirclesService circlesService;

    /**
     * 查询用户圈子列表
     */
    @RequiresPermissions("social:Circles:list")
    @GetMapping("/list")
    public TableDataInfo list(Circles circles)
    {
        startPage();
        List<Circles> list = circlesService.selectCirclesList(circles);
        return getDataTable(list);
    }

    /**
     * 导出用户圈子列表
     */
    @RequiresPermissions("social:Circles:export")
    @Log(title = "用户圈子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Circles circles)
    {
        List<Circles> list = circlesService.selectCirclesList(circles);
        ExcelUtil<Circles> util = new ExcelUtil<Circles>(Circles.class);
        util.exportExcel(response, list, "用户圈子数据");
    }

    /**
     * 获取用户圈子详细信息
     */
    @RequiresPermissions("social:Circles:query")
    @GetMapping(value = "/{circleId}")
    public AjaxResult getInfo(@PathVariable("circleId") Long circleId)
    {
        return success(circlesService.selectCirclesByCircleId(circleId));
    }

    /**
     * 新增用户圈子
     */
    @RequiresPermissions("social:Circles:add")
    @Log(title = "用户圈子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Circles circles)
    {
        return toAjax(circlesService.insertCircles(circles));
    }

    /**
     * 修改用户圈子
     */
    @RequiresPermissions("social:Circles:edit")
    @Log(title = "用户圈子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Circles circles)
    {
        return toAjax(circlesService.updateCircles(circles));
    }

    /**
     * 删除用户圈子
     */
    @RequiresPermissions("social:Circles:remove")
    @Log(title = "用户圈子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{circleIds}")
    public AjaxResult remove(@PathVariable Long[] circleIds)
    {
        return toAjax(circlesService.deleteCirclesByCircleIds(circleIds));
    }
}
